<script setup>
// tab-bar切换
function changeCurrentBarHandle(bar) {
  if (bar === 'me') {
    const token = uni.getStorageSync('token')
    if (!token) {
      uni.navigateTo({ url: '/pages/login/login' })
      return
    }
  }
  let path = `/pages/${bar}/${bar}`
  uni.switchTab({ url: path })
}
</script>

<template>
  <view class="tab-bar">
    <view class="inner">
      <view class="item" @click="changeCurrentBarHandle('home')">
        <view class="icon home"></view>
        <view class="text">首页</view>
      </view>
      <view class="item" @click="changeCurrentBarHandle('publish')">
        <view class="icon publish"></view>
        <view class="text">发布</view>
      </view>
      <view class="item" @click="changeCurrentBarHandle('invite')">
        <view class="icon invite"></view>
        <view class="text">邀请</view>
      </view>
      <view class="item" @click="changeCurrentBarHandle('me')">
        <view class="icon me"></view>
        <view class="text">我的</view>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.tab-bar {
  display: flex;
  align-items: center;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 104rpx;
  color: #a1a1a1;
  background-color: #fff;
  border-top: 2rpx #f0f0f0 solid;

  .inner {
    display: flex;
    width: 100%;
    height: 100%;

    .item {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      flex: 1;
      font-size: 24rpx;

      .icon {
        width: 62rpx;
        height: 62rpx;
        margin-bottom: -5rpx;
      }

      .home {
        background: url('http://recommender.starsky.fun/tpl/Public/xsm/img/tab_icon_home.png') 0 0/62rpx;
      }

      .publish {
        background: url('http://recommender.starsky.fun/tpl/Public/xsm/img/tab_icon_recommend.png') 0 0/62rpx;
      }

      .invite {
        background: url('http://recommender.starsky.fun/tpl/Public/xsm/img/tab_icon_invite.png') 0 0/62rpx;
      }

      .me {
        background: url('http://recommender.starsky.fun/tpl/Public/xsm/img/tab_icon_user.png') 0 0/62rpx;
      }
    }
  }
}
</style>